package testing;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;

import matching.supervisor;

public class SupervisorCreator implements Runnable {
	String configFileS;
	
	 String jdbcURL;
	 String mysqlUser;
	 String mysqlPass;
	 String mysqlDB;
	 String mysqlTable;
	 boolean debug;
	 
	public SupervisorCreator(String _configFile)
	{
		configFileS = _configFile;
	}
	public void run() {
		
		
		Properties configFile = new Properties();
		try {
			configFile.load(new FileInputStream(configFileS));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(configFile.getProperty("DEBUG").equalsIgnoreCase("true"))
			debug = true;
		else
			debug = false;
		
		jdbcURL = "jdbc:mysql://" + configFile.getProperty("URL");
		mysqlUser = configFile.getProperty("MYSQLUSER");
		mysqlPass = configFile.getProperty("MYSQLPASS");
		mysqlDB = configFile.getProperty("MYSQLDB");;
		mysqlTable = configFile.getProperty("MYSQLTABLE");;
		
		ArrayList<String> connectDetails = new ArrayList<String>();
		connectDetails.add(jdbcURL);
		connectDetails.add(mysqlUser);
		connectDetails.add(mysqlPass);
		connectDetails.add(mysqlDB);
		connectDetails.add(mysqlTable);
		
		String multicastGroup = configFile.getProperty("MULTICASTGROUP");
		int multicastPort = Integer.parseInt(configFile.getProperty("MULTICASTPORT"));
		
		int howManySupes = Integer.parseInt(configFile.getProperty("HOWMANYSUPERVISORS"));
		
		int listenPort = Integer.parseInt(configFile.getProperty("listenPort"));
		
		for(int i = 0; i < howManySupes; i++)
		{
			supervisor supe = new supervisor(connectDetails, multicastGroup, multicastPort, listenPort, debug);
			supe.listen();
		}
		
		
		
		
	}
	
}
